package com.house.controller;


import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.house.common.Result;
import com.house.entity.Repair;
import com.house.service.RepairService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;


/**
 * 故障报修管理
 */
@Controller
@RequestMapping("repair")
public class RepairController {

    @Autowired
    RepairService repairService;


    /**
     * 故障报修信息管理页
     * @return
     */
    @GetMapping("manage")
    public String manage() {
        return "admin/repairManage";
    }

    @PostMapping("manage/list")
    @ResponseBody
    public List<Repair> list(Repair repair) {
        return repairService.list(Wrappers.<Repair>query().orderByDesc("create_time"));
    }


    /**
     * 添加/更新故障信息  有ID为更新
     * @param repair
     * @return
     */
    @PostMapping("manage/saveOrUpdate")
    @ResponseBody
    public Result saveOrUpdate(Repair repair){
        repairService.saveOrUpdate(repair);
        return Result.ok();
    }

}
